package com.atguigu.scala.chapter7

import scala.io.Source

/**
 * @author lizikuan
 * @date 2021/5/24 16:43
 */
object $08_WordCountLow {
  def main(args: Array[String]): Unit = {
    //1、读取文件
    val data = Source.fromFile("./datas/data1.txt").getLines().toList
    println(data)
    //2、切割+压平
    val list = data.flatMap(_.split(" "))
    println(list)
    //3、按照单词分组
    val list2 = list.groupBy(x => x)
    println(list2)
    //4、统计次数
    val list3 = list2.map(x => x._1 -> x._2.length).foreach(x=>println(x))
  }
}
